"use strict";

const Service = require("egg").Service;

class oldHouseService extends Service {
  //列表查看
  async oldHouseList(pageIndex, pageSize) {
    const total = await this.app.mysql.select("oldHouse");
    // console.log((pageIndex - 1) * pageSize * 1, pageIndex * pageSize * 1);
    const res = await this.app.mysql.select("oldHouse", {
      // 搜索 post 表
      limit: Number(pageSize * 1), // 返回数据量
      offset: Number((pageIndex - 1) * pageSize * 1), // 数据偏移量
    });
    return { total, res };
  }
  // 添加
  async oldHouseAdd(
    name,
    word,
    region,
    mianji,
    price,
    type,
    company,
    RoleName,
    HouseType,
    phone,
    flag,
    names,
    metro,
    num,
    ip,
    time
  ) {
    const { app } = this;
    await app.mysql.insert("oldHouse", {
      name: name,
      word: word,
      region: region,
      mianji: mianji,
      price: price,
      type: type,
      company: company,
      RoleName: RoleName,
      HouseType: HouseType,
      phone: phone,
      flag: flag,
      names: names,
      metro: metro,
      num: num,
      ip: ip,
      time: time,
    });
    return true;
  }
  // 删除
  async oldHouseDel(id) {
    const { app } = this;
    await app.mysql.delete("oldHouse", {
      id: id,
    });
    return true;
  }
  // 编辑
  async oldHouseSet(obj) {
    const { app } = this;
    await app.mysql.update("oldHouse", obj);
    return true;
  }
}
module.exports = oldHouseService;
